package com.upu173.demo.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

import com.andbase.library.app.base.AbBaseActivity;
import com.andbase.library.utils.AbDialogUtil;
import com.upu173.demo.R;
import com.upu173.qrcode.activity.QRCameraActivity;


public class MainActivity extends AbBaseActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        setToolbarView("最快二维码 Demo",false);

        Button  scanButton = (Button)this.findViewById(R.id.scan_button);
        scanButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(MainActivity.this, QRCameraActivity.class);
                intent.putExtra("cameraId", 0);
                intent.putExtra("orientation", 1);
                startActivityForResult(intent,QRCameraActivity.REQUEST_CODE_QR);
            }
        });

    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if(resultCode == RESULT_OK){
           if(requestCode == QRCameraActivity.REQUEST_CODE_QR){
                Bundle bundle = data.getExtras();
                String qrcode = bundle.getString(QRCameraActivity.RESULT);
                AbDialogUtil.showMessageDialog(MainActivity.this,"扫描结果", qrcode, "确定", new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        AbDialogUtil.removeDialog(MainActivity.this);
                    }
                });

            }
        }
        super.onActivityResult(requestCode, resultCode, data);
    }
}

